package com.example.demo.advice;

import com.example.demo.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class ExceptionAdvice {
    @ExceptionHandler
    public Result<Object> nullException(NullPointerException e){
        log.error("空指针,异常：" ,e);
        return Result.getException(e.getMessage());
    }
    @ExceptionHandler
    public Object artException(ArithmeticException e){
        log.error("算术异常",e);
        return Result.getException(e.getMessage());
    }
    @ExceptionHandler
    public Object exception(Exception e){
        log.error("异常",e);
        return Result.getException(e.getMessage());
    }
}
